package com.cn.demo4.servlet.admin.news;

import com.alibaba.fastjson.JSONObject;
import com.cn.demo4.service.INewsService;
import com.cn.demo4.service.impl.NewsServiceImpl;
import com.cn.demo4.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/news/del")
public class NewsDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.解决乱码
        //2.得到前台传过来的id
        String idString = req.getParameter("id");
        //3.封装数据
        Integer id = Tool.stringToInt(idString);

        //4.调用服务层
        INewsService iNewsService = new NewsServiceImpl();

        //5.得到结果
        int result = iNewsService.del(id);

        //6.返回结果到前台
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        resp.getWriter().println(jsonObject);


    }
}
